using System.Drawing;
using System.Windows.Forms;
using DrawTools.Editor.CanvasFigures;

namespace DrawTools.Editor.Tools.States
{
  internal class ResizeObjectState : IPointerToolState
  {
    private readonly IDrawingCanvas _canvas;
    private readonly CanvasObject _resizedObject;
    private readonly int _resizedObjectHandle;

    public ResizeObjectState(IDrawingCanvas canvas, CanvasObject resizedObject, int resizedObjectHandle)
    {
      _resizedObject = resizedObject;
      _resizedObjectHandle = resizedObjectHandle;
      _canvas = canvas;

      // Since we want to resize only one object, deselect all other objects
      _canvas.GraphicsList.DeselectAll();
      _resizedObject.IsSelected = true;
    }

    #region IPointerToolState Members

    public void Update(Point point)
    {
      if (_resizedObject == null)
        return;

      _resizedObject.MoveHandleTo(point, _resizedObjectHandle, (Control.ModifierKeys & Keys.Shift) != 0);
      _canvas.Refresh();
    }

    public void Release()
    {
      if (_resizedObject != null)
      {
        // after resizing
        _resizedObject.Normalize();
        //_resizedObject = null;
      }
    }

    #endregion
  }
}